import excepetion.NoEnoughPapersException;
import model.*;
import paper.*;
import stategy.RandomSelectionStrategy;
import visitor.*;

import java.util.List;

public class Client {
    public static void main(String[] args) {
        PaperList paperList = new PaperList();

        // 添加测试论文
        paperList.addPaper(new Thesis("基于深度学习的图像识别"));
        paperList.addPaper(new JournalPaper("人工智能发展综述"));
        paperList.addPaper(new ConferencePaper("ICSE 2024 软件工程论文"));
        paperList.addPaper(new JournalPaper("机器学习在医疗中的应用"));

        // 设置策略：随机 or 顺序
        paperList.setStrategy(new RandomSelectionStrategy());

        // 创建学生
        Student student1 = new Student("张三", "JournalPaper", 1);
        Student student2 = new Student("李四", "ConferencePaper", 1);
        Student student3 = new Student("王五", "JournalPaper", 2); // 会抛异常

        PaperSelection selection = new PaperSelection();

        // 测试学生1
        try {
            List<Paper> papers = paperList.selectPaperByStrategy(student1);
            selection.addSelection(student1, papers);
        } catch (NoEnoughPapersException e) {
            System.out.println(e.getMessage());
        }

        // 测试学生2
        try {
            List<Paper> papers = paperList.selectPaperByStrategy(student2);
            selection.addSelection(student2, papers);
        } catch (NoEnoughPapersException e) {
            System.out.println(e.getMessage());
        }

        // 测试学生3（故意选择多于可用数）
        try {
            List<Paper> papers = paperList.selectPaperByStrategy(student3);
            selection.addSelection(student3, papers);
        } catch (NoEnoughPapersException e) {
            System.out.println(e.getMessage());
        }

        // 使用访问者查询
        SelectedCountVisitor visitor = new SelectedCountVisitor();
        selection.accept(visitor);
        System.out.println("已选题的学生数：" + visitor.getCount());
    }
}
